package com.wngbms.aop._06;

import com.wngbms.aop._01.EchoServiceMethodInterceptor;
import com.wngbms.aop.staticproxy.DefaultEchoService;
import com.wngbms.aop.staticproxy.EchoService;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DefaultPointcutAdvisor;

public class PointcutApiDemo {

    public static void main(String[] args) {
        // Advisor 是 Pointcut 和 Advice 之间的桥梁
        EchoServicePointcut pointcut = new EchoServicePointcut("echo", EchoService.class);

        DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(pointcut, new EchoServiceMethodInterceptor());

        DefaultEchoService defaultEchoService = new DefaultEchoService();

        ProxyFactory proxyFactory = new ProxyFactory(defaultEchoService);
        proxyFactory.addAdvisor(advisor);

        EchoService echoService = (EchoService) proxyFactory.getProxy();
        System.out.println(echoService.echo("wngbms"));
    }

}
